//
//  TableViewModel.m
//  DebugDemo
//
//  Created by XFB on 2019/5/7.
//  Copyright © 2019 ZhouCheng. All rights reserved.
//

#import "TableViewModel.h"
#import "TableModel.h"

@implementation TableViewModel

- (instancetype)init
{
    self = [super init];
    if (self) {
        
    }
    return self;
}

- (void)headerRefreshRequestWithCallBack:(CallBack)callBack
{
    dispatch_async(dispatch_get_global_queue(0, 0), ^{
        sleep(2);
        dispatch_async(dispatch_get_main_queue(), ^{
            NSMutableArray *array = @[].mutableCopy;
            for (NSInteger i = 0; i < 15; i ++) {
                NSInteger x = arc4random() % 100;
                NSString *title = [NSString stringWithFormat:@"tableView的第%ld行", x];
                TableModel *tableModel = [[TableModel alloc] init];
                tableModel.title = title;
                [array addObject:tableModel];
            }
            callBack(array);
        });
    });
}

- (void)footerRefreshRequestWithCallBack:(CallBack)callBack
{
    dispatch_async(dispatch_get_global_queue(0, 0), ^{
        sleep(2);
        /// 主线程刷新UI
        dispatch_async(dispatch_get_main_queue(), ^{
            NSMutableArray *array = @[].mutableCopy;
            for (NSInteger i = 0; i < 15; i ++) {
                NSInteger x = arc4random() % 100;
                NSString *title = [NSString stringWithFormat:@"tableView的第%ld行", x];
                TableModel *tableModel = [[TableModel alloc] init];
                tableModel.title = title;
                [array addObject:tableModel];
            }
            callBack(array);
        });
    });
}

@end
